package com.rosiminc.pwt.app;

import org.lwjgl.input.Keyboard;
import org.newdawn.slick.*;

import com.rosiminc.pwt.game.*;

public class PWTApp extends BasicGame {

	private PWTGame game;
	private long currentDelta = 0L;
	private int numRows;
	private int numCols;
	
	private Image playerImg;
	
	private static long SPEED = 100;
	
	public PWTApp(String title, int numCols, int numRows) {
		super(title);
	this.numCols = numCols;
	this.numRows = numRows;
		
		
	}

	@Override
	public void init(GameContainer gc) throws SlickException {
		((AppGameContainer)gc).setDisplayMode(32*numCols, 32*numRows, false);
		game = new PWTGame(numCols, numRows);
		playerImg = new Image("res/sprites/Player.png");
	}

	@Override
	public void update(GameContainer gc, int delta) throws SlickException {
		currentDelta += delta;
		if(currentDelta<SPEED)
			return;
		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
			game.getPlayer().moveDown();
		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
			game.getPlayer().moveUp();
		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
			game.getPlayer().moveLeft();
		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
			game.getPlayer().moveRight();
		currentDelta %= SPEED;
		//TODO Continue from here
	}

	@Override
	public void render(GameContainer gc, Graphics g) throws SlickException {
		playerImg.draw(game.getPlayer().getX()*32, game.getPlayer().getY()*32);
	}

	public static void main(String[] args) throws SlickException
	{
		AppGameContainer app = new AppGameContainer(new PWTApp("Project 'What The...'", 10, 8));
		
		app.setVerbose(false);
		app.setVSync(false);
		app.setTargetFrameRate(60);
		
		app.start();
	}
}
